<template>
  <div>
    <el-row :gutter="20">
      <el-col :span="8">
        <el-card shadow="hover" class="mgb20" style="height:252px;">
          <div class="user-info">
            <img :src="user.userUrl" class="user-avator" alt />
            <div class="user-info-cont">
              <div class="user-info-name">{{ user.username }}</div>
              <div>
                <div v-if="user.role == 1">超级管理员</div>
                <div v-if="user.role == 2">管理员</div>
                <div v-if="user.role == 3">普通用户</div>
              </div>
            </div>
          </div>
          <div class="user-info-list">
            时间：
            <span>{{time}}</span>
          </div>
        </el-card>
        <el-card shadow="hover" style="height:252px;">
          <template #header>
            <div class="clearfix">
              <span>语言详情</span>
            </div>
          </template>
          Vue
          <el-progress :percentage="71.3" color="#42b983"></el-progress>JavaScript
          <el-progress :percentage="24.1" color="#f1e05a"></el-progress>CSS
          <el-progress :percentage="13.7"></el-progress>HTML
          <el-progress :percentage="5.9" color="#f56c6c"></el-progress>
        </el-card>
      </el-col>
      <el-col :span="16">
        <el-row :gutter="20" class="mgb20">
          <el-col :span="6">
            <el-card shadow="hover" :body-style="{ padding: '0px' }">
              <div class="grid-content grid-con-1">
                <i class="el-icon-s-goods grid-con-icon"></i>
                <div class="grid-cont-right">
                  <div class="grid-num">{{num.shop}}</div>
                  <div>商品数量</div>
                </div>
              </div>
            </el-card>
          </el-col>
          <el-col :span="6">
            <el-card shadow="hover" :body-style="{ padding: '0px' }">
              <div class="grid-content grid-con-2">
                <i class="el-icon-s-goods grid-con-icon"></i>
                <div class="grid-cont-right">
                  <div class="grid-num">{{num.seOrder}}</div>
                  <div>出售商品订单数</div>
                </div>
              </div>
            </el-card>
          </el-col>
          <el-col :span="6">
            <el-card shadow="hover" :body-style="{ padding: '0px' }">
              <div class="grid-content grid-con-3">
                <i class="el-icon-s-goods grid-con-icon"></i>
                <div class="grid-cont-right">
                  <div class="grid-num">{{num.order}}</div>
                  <div>购买商品订单数</div>
                </div>
              </div>
            </el-card>
          </el-col>
          <el-col :span="6">
            <el-card shadow="hover" :body-style="{ padding: '0px' }">
              <div class="grid-content grid-con-3">
                <i class="el-icon-shopping-cart-full grid-con-icon"></i>
                <div class="grid-cont-right">
                  <div class="grid-num">{{ num.collect }}</div>
                  <div>购物车数量</div>
                </div>
              </div>
            </el-card>
          </el-col>
        </el-row>
        <el-card shadow="hover" style="height:403px;">
          <template #header>
            <div class="clearfix">
              <span>待办事项</span>
<!--              <el-button style="float: right; padding: 3px 0" type="text">添加</el-button>-->
            </div>
          </template>

          <el-table :show-header="false" :data="todoList" style="width:100%;">
            <el-table-column width="40">
              <template #default="scope">
                <el-checkbox v-model="scope.row.status"></el-checkbox>
              </template>
            </el-table-column>
            <el-table-column>
              <template #default="scope">
                <div
                  class="todo-item"
                  :class="{
                                        'todo-item-del': scope.row.status,
                                    }"
                >{{ scope.row.title }}</div>
              </template>
            </el-table-column>
            <el-table-column width="60">
              <template>
<!--                <i class="el-icon-edit"></i>-->
<!--                <i class="el-icon-delete"></i>-->
              </template>
            </el-table-column>
          </el-table>
        </el-card>
      </el-col>
    </el-row>
    <el-row :gutter="20" class="mgb20" v-if="user.role == 1">
      <el-col :span="12">
        <el-card shadow="hover" :body-style="{ padding: '0px' }">
          <div class="grid-content grid-con-1">
            <i class="el-icon-user-solid grid-con-icon"></i>
            <div class="grid-cont-right">
              <div class="grid-num">{{numEr.user}}</div>
              <div>用户数量</div>
            </div>
          </div>
        </el-card>
      </el-col>
      <el-col :span="12">
        <el-card shadow="hover" :body-style="{ padding: '0px' }">
          <div class="grid-content grid-con-2">
            <i class="el-icon-s-tools grid-con-icon"></i>
            <div class="grid-cont-right">
              <div class="grid-num">{{numEr.tab}}</div>
              <div>商品类型数量</div>
            </div>
          </div>
        </el-card>
      </el-col>
    </el-row>
    <el-row :gutter="20" class="mgb20">
      <el-col :span="8">
        <el-card shadow="hover" :body-style="{ padding: '0px' }">
          <div class="grid-content grid-con-1">
            <i class="el-icon-s-goods grid-con-icon"></i>
            <div class="grid-cont-right">
              <div class="grid-num">{{numSan.shop}}</div>
              <div>总商品数量</div>
            </div>
          </div>
        </el-card>
      </el-col>
      <el-col :span="8">
        <el-card shadow="hover" :body-style="{ padding: '0px' }">
          <div class="grid-content grid-con-2">
            <i class="el-icon-s-goods grid-con-icon"></i>
            <div class="grid-cont-right">
              <div class="grid-num">{{numSan.order}}</div>
              <div>总商品订单数</div>
            </div>
          </div>
        </el-card>
      </el-col>
      <el-col :span="8">
        <el-card shadow="hover" :body-style="{ padding: '0px' }">
          <div class="grid-content grid-con-3">
            <i class="el-icon-shopping-cart-full grid-con-icon"></i>
            <div class="grid-cont-right">
              <div class="grid-num">{{ numSan.collect }}</div>
              <div>总购物车数量</div>
            </div>
          </div>
        </el-card>
      </el-col>
    </el-row>
  </div>
</template>

<script>
export default {
  name: 'Welcome',
  data(){
    return{
      user: {},
      time: '',
      num:{},
      numEr:{},
      numSan: {},
      todoList: [
        {
          title: "今天要修复100个bug",
          status: false
        },
        {
          title: "今天要修复100个bug",
          status: false
        },
        {
          title: "今天要写100行代码加几个bug吧",
          status: false
        },
        {
          title: "今天要修复100个bug",
          status: false
        },
        {
          title: "今天要修复100个bug",
          status: true
        },
        {
          title: "今天要写100行代码加几个bug吧",
          status: true
        }
      ],
      data: [
        {
          name: "2018/09/04",
          value: 1083
        },
        {
          name: "2018/09/05",
          value: 941
        },
        {
          name: "2018/09/06",
          value: 1139
        },
        {
          name: "2018/09/07",
          value: 816
        },
        {
          name: "2018/09/08",
          value: 327
        },
        {
          name: "2018/09/09",
          value: 228
        },
        {
          name: "2018/09/10",
          value: 1065
        }
      ],
    }
  },
  created() {
    this.getUser()
    this.getCurrentTime()
    this.timer = setInterval(() => {
      this.getCurrentTime();
    }, 1000)
  },
  methods:{
    getUser() {
      let user = JSON.parse(window.sessionStorage.getItem('user') || null)
      if (user){
        this.user = user
        this.getLu()
        if (user.role == 1){
          this.getLu2()
        }
        if (user.role <= 2){
          this.getLu3()
        }
      }
    },
    getCurrentTime() {
      var date = new Date()
      let weeks = ['星期日', '星期一', '星期二', '星期三', '星期四', '星期五', '星期六'];

      var year = date.getFullYear()
      var month = date.getMonth() + 1
      var day = date.getDate()
      month = month > 9 ? month : '0' + month
      day = day > 9 ? day : '0' + day
      var hour = date.getHours()
      var minutes = date.getMinutes()
      var seconds = date.getSeconds()
      if(minutes<10){
        minutes='0'+minutes
      }
      if(seconds<10){
        seconds='0'+seconds
      }
      this.time = year + '-' + month + '-' + day + ' '+hour + ':' + minutes + ':' + seconds + ' '+weeks[date.getDay()]
      // console.log(this.hours)
    },
    showTimes() {
      setInterval(this.getCurrentTime(),1000)
    },
    async getLu(){
      let that = this
      let dataId = {
        userId: this.user.id,
        sellerId: this.user.id
      }
      const { data: res } = await this.$http.post('user/num', dataId);
      if(res.flag == "200") {
        this.num = res

      }
    },
    async getLu2(){
      let that = this
      const { data: res } = await this.$http.post('user/num2');
      if(res.flag == "200") {
        that.numEr = res
      }
    },
    async getLu3(){
      let that = this
      const { data: res } = await this.$http.post('user/num3');
      if(res.flag == "200") {
        that.numSan = res
      }
    }
  }
};
</script>

<style lang="less" scoped>
.el-row {
  margin-bottom: 20px;
}

.grid-content {
  display: flex;
  align-items: center;
  height: 100px;
}

.grid-cont-right {
  flex: 1;
  text-align: center;
  font-size: 14px;
  color: #999;
}

.grid-num {
  font-size: 30px;
  font-weight: bold;
}

.grid-con-icon {
  font-size: 50px;
  width: 100px;
  height: 100px;
  text-align: center;
  line-height: 100px;
  color: #fff;
}

.grid-con-1 .grid-con-icon {
  background: rgb(45, 140, 240);
}

.grid-con-1 .grid-num {
  color: rgb(45, 140, 240);
}

.grid-con-2 .grid-con-icon {
  background: rgb(100, 213, 114);
}

.grid-con-2 .grid-num {
  color: rgb(45, 140, 240);
}

.grid-con-3 .grid-con-icon {
  background: rgb(242, 94, 67);
}

.grid-con-3 .grid-num {
  color: rgb(242, 94, 67);
}

.user-info {
  display: flex;
  align-items: center;
  padding-bottom: 20px;
  border-bottom: 2px solid #ccc;
  margin-bottom: 20px;
}

.user-avator {
  width: 120px;
  height: 120px;
  border-radius: 50%;
}

.user-info-cont {
  padding-left: 50px;
  flex: 1;
  font-size: 14px;
  color: #999;
}

.user-info-cont div:first-child {
  font-size: 30px;
  color: #222;
}

.user-info-list {
  font-size: 14px;
  color: #999;
  line-height: 25px;
}

.user-info-list span {
  margin-left: 70px;
}

.mgb20 {
  margin-bottom: 20px;
}

.todo-item {
  font-size: 14px;
}

.todo-item-del {
  text-decoration: line-through;
  color: #999;
}
</style>
